package com.example.x6.configurationmaintenance.Activity;

import android.app.ProgressDialog;
import android.os.Bundle;
import android.os.Handler;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceCategory;
import android.support.annotation.Nullable;
import com.example.x6.configurationmaintenance.Dialog.MessageDialog;
import com.example.x6.configurationmaintenance.Dialog.PowerOffDialog;
import com.example.x6.configurationmaintenance.Dialog.YesOrNoDialog;
import com.example.x6.configurationmaintenance.Interface.BootanimationListener.OnBootanimationFindListener;
import com.example.x6.configurationmaintenance.Interface.BootanimationListener.OnBootanimationReplaceListener;
import com.example.x6.configurationmaintenance.Interface.BootanimationListener.OnBootanimationResetFinishListener;
import com.example.x6.configurationmaintenance.Interface.OnYesOrNoClick;
import com.example.x6.configurationmaintenance.Module.BootanimationManager;
import com.example.x6.configurationmaintenance.R;

public class ReplaceBootanimation extends PreferenceActivity {
    private final String TAG = getClass().getSimpleName();
    private BootanimationManager bootanimationManager;
    private Handler handler;
    private PreferenceCategory preferenceCategory;
    private Preference resetBootanimation;

    /* access modifiers changed from: protected */
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.replace_bootanimation);
        this.bootanimationManager = new BootanimationManager();
        this.preferenceCategory = (PreferenceCategory) findPreference(getResources().getString(R.string.bootanimation_replace));
        this.resetBootanimation = getPreferenceScreen().findPreference(getResources().getString(R.string.reset_bootanimation));
        this.handler = new Handler();
        this.resetBootanimation.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
            /* class com.example.x6.configurationmaintenance.Activity.ReplaceBootanimation.AnonymousClass1 */

            public boolean onPreferenceClick(Preference preference) {
                final ProgressDialog progressDialog = new ProgressDialog(ReplaceBootanimation.this);
                progressDialog.setTitle(ReplaceBootanimation.this.getResources().getString(R.string.tips));
                progressDialog.setMessage(ReplaceBootanimation.this.getResources().getString(R.string.restoring_bootanimation));
                progressDialog.show();
                ReplaceBootanimation.this.bootanimationManager.setBootanimationResetFinishListener(new OnBootanimationResetFinishListener() {
                    /* class com.example.x6.configurationmaintenance.Activity.ReplaceBootanimation.AnonymousClass1.AnonymousClass1 */

                    @Override // com.example.x6.configurationmaintenance.Interface.BootanimationListener.OnBootanimationResetFinishListener
                    public void bootanimationResetFinished(final boolean isOk) {
                        ReplaceBootanimation.this.handler.post(new Runnable() {
                            /* class com.example.x6.configurationmaintenance.Activity.ReplaceBootanimation.AnonymousClass1.AnonymousClass1.AnonymousClass1 */

                            public void run() {
                                progressDialog.dismiss();
                                if (isOk) {
                                    new PowerOffDialog(ReplaceBootanimation.this).showDialog();
                                    return;
                                }
                                MessageDialog messageDialog = new MessageDialog(ReplaceBootanimation.this);
                                messageDialog.setMessage(ReplaceBootanimation.this.getResources().getString(R.string.restore_failed));
                                messageDialog.showDialog();
                            }
                        });
                    }
                });
                return true;
            }
        });
    }

    /* access modifiers changed from: protected */
    public void onResume() {
        super.onResume();
        this.bootanimationManager.setBootanimationFindListener(new OnBootanimationFindListener() {
            /* class com.example.x6.configurationmaintenance.Activity.ReplaceBootanimation.AnonymousClass2 */

            @Override // com.example.x6.configurationmaintenance.Interface.BootanimationListener.OnBootanimationFindListener
            public void bootanimationFind(final String path) {
                if (!path.equals("/system/media/bootanimation.zip")) {
                    Preference tempPreference = new Preference(ReplaceBootanimation.this);
                    tempPreference.setTitle(path);
                    tempPreference.setSummary(ReplaceBootanimation.this.getResources().getString(R.string.bootanimation_preference_summary));
                    tempPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
                        /* class com.example.x6.configurationmaintenance.Activity.ReplaceBootanimation.AnonymousClass2.AnonymousClass1 */

                        public boolean onPreferenceClick(Preference preference) {
                            YesOrNoDialog yesOrNoDialog = new YesOrNoDialog(ReplaceBootanimation.this);
                            yesOrNoDialog.setTitle(ReplaceBootanimation.this.getResources().getString(R.string.tips));
                            yesOrNoDialog.setMessage(ReplaceBootanimation.this.getResources().getString(R.string.replace_danger_warning));
                            yesOrNoDialog.setOnYesOrNoClick(new OnYesOrNoClick() {
                                /* class com.example.x6.configurationmaintenance.Activity.ReplaceBootanimation.AnonymousClass2.AnonymousClass1.AnonymousClass1 */

                                @Override // com.example.x6.configurationmaintenance.Interface.OnYesOrNoClick
                                public void onYesPressed() {
                                    final ProgressDialog progressDialog = new ProgressDialog(ReplaceBootanimation.this);
                                    progressDialog.setTitle(ReplaceBootanimation.this.getResources().getString(R.string.tips));
                                    progressDialog.setMessage(ReplaceBootanimation.this.getResources().getString(R.string.replacing_bootanimation));
                                    progressDialog.show();
                                    ReplaceBootanimation.this.bootanimationManager.setBootanimationReplaceListener(new OnBootanimationReplaceListener() {
                                        /* class com.example.x6.configurationmaintenance.Activity.ReplaceBootanimation.AnonymousClass2.AnonymousClass1.AnonymousClass1.AnonymousClass1 */

                                        @Override // com.example.x6.configurationmaintenance.Interface.BootanimationListener.OnBootanimationReplaceListener
                                        public void bootanimationRelpaced(boolean isOk) {
                                            if (isOk) {
                                                ReplaceBootanimation.this.handler.post(new Runnable() {
                                                    /* class com.example.x6.configurationmaintenance.Activity.ReplaceBootanimation.AnonymousClass2.AnonymousClass1.AnonymousClass1.AnonymousClass1.AnonymousClass1 */

                                                    public void run() {
                                                        progressDialog.dismiss();
                                                        new PowerOffDialog(ReplaceBootanimation.this).showDialog();
                                                    }
                                                });
                                            } else {
                                                ReplaceBootanimation.this.handler.post(new Runnable() {
                                                    /* class com.example.x6.configurationmaintenance.Activity.ReplaceBootanimation.AnonymousClass2.AnonymousClass1.AnonymousClass1.AnonymousClass1.AnonymousClass2 */

                                                    public void run() {
                                                        progressDialog.dismiss();
                                                        MessageDialog messageDialog = new MessageDialog(ReplaceBootanimation.this);
                                                        messageDialog.setMessage(ReplaceBootanimation.this.getResources().getString(R.string.replace_failed));
                                                        messageDialog.showDialog();
                                                    }
                                                });
                                            }
                                        }
                                    }, path);
                                }

                                @Override // com.example.x6.configurationmaintenance.Interface.OnYesOrNoClick
                                public void onNoPressed() {
                                }
                            });
                            yesOrNoDialog.showDialog();
                            return true;
                        }
                    });
                    ReplaceBootanimation.this.preferenceCategory.addPreference(tempPreference);
                }
            }

            @Override // com.example.x6.configurationmaintenance.Interface.BootanimationListener.OnBootanimationFindListener
            public void bootanimationFindFinished(boolean isEmpty) {
                if (isEmpty) {
                    Preference tempPreference = new Preference(ReplaceBootanimation.this);
                    tempPreference.setTitle(ReplaceBootanimation.this.getResources().getString(R.string.warning));
                    tempPreference.setSummary(ReplaceBootanimation.this.getResources().getString(R.string.bootanimation_not_found));
                    ReplaceBootanimation.this.preferenceCategory.addPreference(tempPreference);
                }
            }
        });
    }

    /* access modifiers changed from: protected */
    public void onPause() {
        super.onPause();
    }

    private void mDelay(long mill) {
        try {
            Thread.sleep(mill);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
